const jwt = require('jsonwebtoken')
const config = require('../config')

// 生成Token
exports.generateToken = (userId, role) => {
  return jwt.sign({ userId, role }, config.jwtSecret, { expiresIn: config.jwtExpiresIn })
}

// 验证Token
exports.verifyToken = token => {
  try {
    return jwt.verify(token, config.jwtSecret)
  } catch (err) {
    return null
  }
}
